package Comment

import (
	"FromNowOnPromote/博客系统/Tblog/models"
	"log"
)

type UserComment struct {
	Id      int    `gorm:"AUTO_INCREMENT;PRIMARY_KEY"`
	BId     int    `gorm:"type:int(20);not null"` //博客Id
	Content string `gorm:"type:varchar(255)"`     //评论内容
	FromId  int    `gorm:"not null"`              //评论用户Id
	ToId    int    `gorm:"not null"`              //评论目标Id
}

//设置表名
func (UserComment) TableName() string {
	return "usercomment"
}

func init() {
	db := models.ConnDb()
	//判断表是否存在
	bl := db.HasTable(&UserComment{})
	if bl == false {
		db.CreateTable(&UserComment{})
	} else {
		err := db.AutoMigrate(&UserComment{}).Error
		if err != nil {
			log.Fatal(err)
		}
	}
}
